package com.charger.cooperation.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.charger.chargingStation.mapper.ChargingstationMapper;
import com.charger.common.utils.DateUtils;
import com.charger.cooperation.domain.*;
import com.charger.cooperation.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.charger.cooperation.service.IInvestorsService;

/**
 * 投资商管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-22
 */
@Service
public class InvestorsServiceImpl extends ServiceImpl<InvestorsMapper ,Investors>
        implements IInvestorsService
{
    @Autowired
    private InvestorsMapper investorsMapper;
    @Autowired
    InvestorsProjectsMapper investorsProjectsMapper;
    @Autowired
    ProjectsMapper projectsMapper;
    @Autowired
     LChargingstationMapper chargingstationMapper;

    @Autowired
    InvestorsChargingstationMapper investorsChargingstationMapper;

    /**
     * 查询投资商管理
     * 
     * @param investorId 投资商管理主键
     * @return 投资商管理
     */
    @Override
    public Investors selectInvestorsByInvestorId(Long investorId)
    {
        Investors investors = investorsMapper.selectInvestorsByInvestorId(investorId);
        QueryWrapper<InvestorsProjects> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("investors", investors.getInvestorId());
        List<InvestorsProjects> investorsProjects = investorsProjectsMapper.selectList(queryWrapper);

        if (investorsProjects != null){
            investorsProjects.forEach(item->{
                Projects projects = projectsMapper.selectOne(new QueryWrapper<Projects>().eq("projects_id", item.getProjects()));
                System.out.println(projects);
                investors.getProjectsList().add(projects);
            });
        }

        List<InvestorsChargingstation> investorsChargingstations = investorsChargingstationMapper.selectList(
                new QueryWrapper<InvestorsChargingstation>().eq("investors_id", investors.getInvestorId()));
        investorsChargingstations.forEach(investorsChargingstation -> {
            LChargingstation chargingstation = chargingstationMapper.selectById(investorsChargingstation.getChargingstationId());
            investors.getChargingstationList().add(chargingstation);
        });
        return investors;
    }

    /**
     * 查询投资商管理列表
     * 
     * @param investors 投资商管理
     * @return 投资商管理
     */
    @Override
    public List<Investors> selectInvestorsList(Investors investors)
    {
        return investorsMapper.selectInvestorsList(investors);
    }

    /**
     * 新增投资商管理
     * 
     * @param investors 投资商管理
     * @return 结果
     */
    @Override
    public int insertInvestors(Investors investors)
    {
        investors.setCreateTime(DateUtils.getNowDate());
        return investorsMapper.insertInvestors(investors);
    }

    /**
     * 修改投资商管理
     * 
     * @param investors 投资商管理
     * @return 结果
     */
    @Override
    public int updateInvestors(Investors investors)
    {
        return investorsMapper.updateInvestors(investors);
    }

    /**
     * 批量删除投资商管理
     * 
     * @param investorIds 需要删除的投资商管理主键
     * @return 结果
     */
    @Override
    public int deleteInvestorsByInvestorIds(Long[] investorIds)
    {
        return investorsMapper.deleteInvestorsByInvestorIds(investorIds);
    }

    /**
     * 删除投资商管理信息
     * 
     * @param investorId 投资商管理主键
     * @return 结果
     */
    @Override
    public int deleteInvestorsByInvestorId(Long investorId)
    {
        return investorsMapper.deleteInvestorsByInvestorId(investorId);
    }
}
